package com.dubito.concurrency.example.singleton;

import com.dubito.concurrency.annotation.Recommend;
import com.dubito.concurrency.annotation.ThreadSafe;

/**
 * @author liliang
 * @description: 饿汉模式 推荐使用 枚举模式
 * @date 2018/6/24.
 */
@ThreadSafe
@Recommend
public class SingletonExample7 {

    /**
     * 私有构造
     */
    private SingletonExample7() {

    }

    /**
     * 静态的工厂方法
     *
     * @return
     */
    public static SingletonExample7 getInstance() {
        return Singleton.INSTANCE.getSingleton();
    }

    private enum Singleton {
        INSTANCE;

        private SingletonExample7 singleton;

        Singleton() {
            singleton = new SingletonExample7();
        }

        public SingletonExample7 getSingleton() {
            return singleton;
        }
    }
}
